#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int i = (a);i <= (b);++i)
#define per(i,a,b) for(int i = (a);i >= (b);--i) 
#define mkp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
inline bool cmp(int x,int y){return x < y;}
/* -fsanitize=undefined  */
const int N = 5e5+9;
const int inf = 1e9+9;
const double eps = 1e-7;
int _,n,m,root,a,b,u,v,d;
int fa[2*N][20],depth[2*N];

int head[2*N],next[2*N],ver[2*N],tot;
inline void link(int x,int y){ver[++tot] = y , next[tot] = head[x] , head[x] = tot;}

inline void dfs(int now,int father){
    depth[now] = depth[father] + 1 , fa[now][0] = father;
    for(int i = head[now];i;i = next[i]) if(ver[i] != father) dfs(ver[i] , now);
}

inline ll LCA(){
    if(depth[u] < depth[v]) std::swap(u,v);
    per(i,d,0) if(depth[ fa[u][i] ] >= depth[v]) u = fa[u][i];
    if(u == v) return u;
    per(i,d,0) if(fa[u][i] != fa[v][i]) u = fa[u][i] , v = fa[v][i];
    return fa[u][0];
} 

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef LOCAL //  -DLOCAL
        freopen("in.in", "r", stdin);
    #endif
    cin >> n >> m >> root;
    d = (std::log(n) / std::log(2)) + 1;
    rep(i,1,n-1){
        cin >> u >> v;
        link(u,v) , link(v,u);
    }
    depth[0] = -1;
    dfs(root,0);
    fa[root][0] = root;
    rep(j,1,d) rep(i,1,n) fa[i][j] = fa[ fa[i][j-1] ][j-1];
    rep(i,1,m){
        cin >> u >> v;
        cout << LCA() << "\n";
    }

    return 0;
}